#ifndef TIMESLOT_H
#define TIMESLOT_H

#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/shared_ptr.hpp>

typedef boost::posix_time::ptime Ptime;
typedef boost::shared_ptr<Ptime> PtimePtr;


class TimeSlot
{
public:
  TimeSlot(const PtimePtr _start_time, const PtimePtr _end_time)
    : start_time(_start_time), end_time(_end_time)
  { }

  const PtimePtr
  getStartTime() const
  {
    return start_time;
  }

  const PtimePtr
  getEndTime() const
  {
    return end_time;
  }

private:
  PtimePtr start_time;
  PtimePtr end_time;
};


typedef boost::shared_ptr<TimeSlot> TimeSlotPtr;
typedef std::vector<TimeSlotPtr> TimeSlots;
typedef boost::shared_ptr<TimeSlots> TimeSlotsPtr;


std::ostream&
operator<< (std::ostream& os, const PtimePtr& pt)
{
  os << *pt;
  return os;
}


std::ostream&
operator<< (std::ostream& os, const TimeSlot& ts)
{
  os << "(" << ts.getStartTime() << " to " << ts.getEndTime() << ")";
  return os;
}


std::ostream&
operator<< (std::ostream& os, const TimeSlotPtr& ts)
{
  os << *ts;
  return os;
}


class CompareTimeSlots
{
public:
  bool
  operator() (const TimeSlotPtr& ts1, const TimeSlotPtr& ts2)
  {
    PtimePtr ts1_start = ts1->getStartTime();
    PtimePtr ts1_end = ts1->getEndTime();
    PtimePtr ts2_start = ts2->getStartTime();
    PtimePtr ts2_end = ts2->getEndTime();

    return (  ( ((*ts2_start) <= (*ts1_start)) && ((*ts1_end) >= (*ts2_end)) ) 
           || ( ((*ts1_start) <= (*ts2_start)) && ((*ts2_end) >= (*ts1_end)) ) );
  }
};

#endif

// Local Variables:
// mode: C++
// End:
